﻿using B.S.Meeting.Domain;
using B.S.Meeting.ErrorCode;
using B.S.Meeting.ReadAPI.Applications.Commands.MeetingReservations;
using B.S.Meeting.ReadAPI.Applications.Commands.MeetingRooms;
using B.S.Meeting.ReadAPI.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Meeting.ReadAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReservationController : ControllerBase
    {
        IMediator mediator;
        ILogger<ReservationController> logger;

        public ReservationController(IMediator mediator, ILogger<ReservationController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 获取会议室位置
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<IList<MeetingRoom>>> SelectRoom()
        {
            try
            {
                SelectRoomCommand cmd= new SelectRoomCommand();
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取会议预约列表
        /// </summary>
        /// <param name="cmd">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<List<ReservationDto>>>> GetReservation([FromQuery]GetReservationCommand cmd)
        {
            try
            {
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取会议详情
        /// </summary>
        /// <param name="reservationId">会议预约ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<ReservationDto>>> GetReserDetail([FromQuery]int reservationId)
        {
            try
            {
                GetReservationDetailCommand cmd = new GetReservationDetailCommand
                {
                    MeetingReservationId = reservationId
                };
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
